#include <glib.h>

void _list_interger_print_func(gpointer data, gpointer user_data)
{
    g_print("data is: %d, user_data is: %s \n", GPOINTER_TO_INT(data), (gchar *)user_data);
}

gint _list_interger_cmp_func(gconstpointer a, gconstpointer b)
{
    return GPOINTER_TO_INT(a) - GPOINTER_TO_INT(b);
}

gint main(gint argc, gchar **argv)
{
    GList *list = NULL;

    list = g_list_append(list, GINT_TO_POINTER(1));
    list = g_list_append(list, GINT_TO_POINTER(5));
    list = g_list_append(list, GINT_TO_POINTER(3));
    list = g_list_append(list, GINT_TO_POINTER(7));

    g_list_foreach(list, _list_interger_print_func, (gchar *)"before insert_sorted");

    list = g_list_insert_sorted(list, GINT_TO_POINTER(4), _list_interger_cmp_func);

    g_list_foreach(list, _list_interger_print_func, (gchar *)"after insert_sorted");

    list = g_list_sort(list, _list_interger_cmp_func);

    g_list_foreach(list, _list_interger_print_func, (gchar *)"after sorted");

    g_list_free(list);

    return 0;
}